{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "from dl_util import *\n",
    "from ml_util import *\n",
    "from run_eval import split_fit_plot_predict\n",
    "from eval_class_util import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loading Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('eval_datasets/HIV.csv')\n",
    "hiv = df[pd.notnull(df['HIV_active'])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>smiles</th>\n",
       "      <th>activity</th>\n",
       "      <th>HIV_active</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CCC1=[O+][Cu-3]2([O+]=C(CC)C1)[O+]=C(CC)CC(CC)...</td>\n",
       "      <td>CI</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>C(=Cc1ccccc1)C1=[O+][Cu-3]2([O+]=C(C=Cc3ccccc3...</td>\n",
       "      <td>CI</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CC(=O)N1c2ccccc2Sc2c1ccc1ccccc21</td>\n",
       "      <td>CI</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nc1ccc(C=Cc2ccc(N)cc2S(=O)(=O)O)c(S(=O)(=O)O)c1</td>\n",
       "      <td>CI</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>O=S(=O)(O)CCS(=O)(=O)O</td>\n",
       "      <td>CI</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              smiles activity  HIV_active\n",
       "0  CCC1=[O+][Cu-3]2([O+]=C(CC)C1)[O+]=C(CC)CC(CC)...       CI           0\n",
       "1  C(=Cc1ccccc1)C1=[O+][Cu-3]2([O+]=C(C=Cc3ccccc3...       CI           0\n",
       "2                   CC(=O)N1c2ccccc2Sc2c1ccc1ccccc21       CI           0\n",
       "3    Nc1ccc(C=Cc2ccc(N)cc2S(=O)(=O)O)c(S(=O)(=O)O)c1       CI           0\n",
       "4                             O=S(=O)(O)CCS(=O)(=O)O       CI           0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hiv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "hiv_true = hiv[hiv['HIV_active']==1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "hiv_false_selected = hiv[hiv['HIV_active']== 0][:1443]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "hiv_smiles = hiv_true['smiles'].tolist()+hiv_false_selected['smiles'].tolist()\n",
    "hiv_active = hiv_true['HIV_active'].tolist()+hiv_false_selected['HIV_active'].tolist()\n",
    "hiv_indices = np.concatenate((hiv_true.index.values,hiv_false_selected.index.values))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "hiv_maccs_all = loadNumpy('maccs_hiv_all')\n",
    "hiv_maccs = []\n",
    "for i in hiv_indices:\n",
    "    hiv_maccs += [hiv_maccs_all[i]]\n",
    "hiv_maccs = np.array(hiv_maccs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    41127.000000\n",
       "mean         0.035086\n",
       "std          0.184001\n",
       "min          0.000000\n",
       "25%          0.000000\n",
       "50%          0.000000\n",
       "75%          0.000000\n",
       "max          1.000000\n",
       "Name: HIV_active, dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hiv['HIV_active'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2886, 2886, 2886)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(hiv_smiles), len(hiv_active), len(hiv_indices)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "saveData(hiv_smiles, 'hiv_smiles_2886')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Preparation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(54, 400)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len_hiv_smiles = []\n",
    "for SMILE in hiv_smiles:\n",
    "    len_hiv_smiles += [len(SMILE)]\n",
    "    \n",
    "max_len_hiv = max(len_hiv_smiles)\n",
    "\n",
    "hiv_vocab_size = generate_onehot_encoding(hiv_smiles,'vocab_size')\n",
    "hiv_vocab_size, max_len_hiv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "hiv_encodings = generate_onehot_encoding(hiv_smiles)\n",
    "hiv_sequences = sequence.pad_sequences(hiv_encodings, maxlen=max_len_hiv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "X1 = hiv_sequences\n",
    "X2 = hiv_maccs \n",
    "Y =  hiv_active\n",
    "# X1_train_hiv, X1_test_hiv, y_train_hiv, y_test_hiv = train_test_split(X1_hiv, Y_hiv, random_state=1024)\n",
    "# X2_train_hiv, X2_test_hiv, y_train_hiv, y_test_hiv = train_test_split(X2_hiv, Y_hiv, random_state=1024)\n",
    "saveNumpy(hiv_sequences, 'hiv_sequences')\n",
    "saveNumpy(hiv_maccs, 'hiv_maccs' )\n",
    "saveNumpy(hiv_active, 'hiv_active')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "hiv_maccs = loadNumpy('hiv_maccs')\n",
    "hiv_sequences = loadNumpy('hiv_sequences')\n",
    "hiv_active = loadNumpy('hiv_active')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "hiv_vocab_size, max_len_hiv = 54,400"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cnn_model\n",
      "classification\n",
      "++++++++++++++\n",
      "WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py:497: calling conv1d (from tensorflow.python.ops.nn_ops) with data_format=NHWC is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "`NHWC` for data_format is deprecated, use `NWC` instead\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_1 (Embedding)      (None, 400, 32)           1728      \n",
      "_________________________________________________________________\n",
      "conv1d_1 (Conv1D)            (None, 400, 32)           3104      \n",
      "_________________________________________________________________\n",
      "max_pooling1d_1 (MaxPooling1 (None, 200, 32)           0         \n",
      "_________________________________________________________________\n",
      "conv1d_2 (Conv1D)            (None, 200, 32)           3104      \n",
      "_________________________________________________________________\n",
      "max_pooling1d_2 (MaxPooling1 (None, 100, 32)           0         \n",
      "_________________________________________________________________\n",
      "flatten_1 (Flatten)          (None, 3200)              0         \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 1)                 3201      \n",
      "=================================================================\n",
      "Total params: 11,137\n",
      "Trainable params: 11,137\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 1947 samples, validate on 217 samples\n",
      "Epoch 1/5\n",
      "1888/1947 [============================>.] - ETA: 0s - loss: 0.6080 - acc: 0.6626 - precision: 0.5099 - recall: 0.9979 - auc: 0.6577"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-6-0dfd9e390069>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msplit_fit_plot_predict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcnn_model\u001b[0m\u001b[0;34m,\u001b[0m  \u001b[0mhiv_sequences\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhiv_maccs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhiv_active\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhiv_vocab_size\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_len_hiv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"hiv\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/home/apx748/CEP/run_eval.pyc\u001b[0m in \u001b[0;36msplit_fit_plot_predict\u001b[0;34m(model_arch, X1, X2, Y, vocab, max_len, prefix, dropout, gate, optimizer, lr, epochs, batch_size)\u001b[0m\n\u001b[1;32m     57\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     58\u001b[0m         history = model.fit(X1_train, y_train, shuffle=True, validation_split=0.1,\\\n\u001b[0;32m---> 59\u001b[0;31m                         epochs=epochs, batch_size=batch_size, verbose=1, callbacks=[early_stop])\n\u001b[0m\u001b[1;32m     60\u001b[0m         \u001b[0mX_test\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mX1_test\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     61\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/keras/models.pyc\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)\u001b[0m\n\u001b[1;32m   1000\u001b[0m                               \u001b[0minitial_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minitial_epoch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1001\u001b[0m                               \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1002\u001b[0;31m                               validation_steps=validation_steps)\n\u001b[0m\u001b[1;32m   1003\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1004\u001b[0m     def evaluate(self, x=None, y=None,\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/keras/engine/training.pyc\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)\u001b[0m\n\u001b[1;32m   1703\u001b[0m                               \u001b[0minitial_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minitial_epoch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1704\u001b[0m                               \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1705\u001b[0;31m                               validation_steps=validation_steps)\n\u001b[0m\u001b[1;32m   1706\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1707\u001b[0m     def evaluate(self, x=None, y=None,\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/keras/engine/training.pyc\u001b[0m in \u001b[0;36m_fit_loop\u001b[0;34m(self, f, ins, out_labels, batch_size, epochs, verbose, callbacks, val_f, val_ins, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps)\u001b[0m\n\u001b[1;32m   1234\u001b[0m                         \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtoarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1235\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1236\u001b[0;31m                     \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mins_batch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1237\u001b[0m                     \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mouts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1238\u001b[0m                         \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mouts\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.pyc\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m   2480\u001b[0m         \u001b[0msession\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_session\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2481\u001b[0m         updated = session.run(fetches=fetches, feed_dict=feed_dict,\n\u001b[0;32m-> 2482\u001b[0;31m                               **self.session_kwargs)\n\u001b[0m\u001b[1;32m   2483\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mupdated\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2484\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[1;32m    903\u001b[0m     \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    904\u001b[0m       result = self._run(None, fetches, feed_dict, options_ptr,\n\u001b[0;32m--> 905\u001b[0;31m                          run_metadata_ptr)\n\u001b[0m\u001b[1;32m    906\u001b[0m       \u001b[0;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    907\u001b[0m         \u001b[0mproto_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36m_run\u001b[0;34m(self, handle, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[1;32m   1123\u001b[0m     \u001b[0;31m# Create a fetch handler to take care of the structure of fetches.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1124\u001b[0m     fetch_handler = _FetchHandler(\n\u001b[0;32m-> 1125\u001b[0;31m         self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles)\n\u001b[0m\u001b[1;32m   1126\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1127\u001b[0m     \u001b[0;31m# Run request and get response.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, graph, fetches, feeds, feed_handles)\u001b[0m\n\u001b[1;32m    425\u001b[0m     \"\"\"\n\u001b[1;32m    426\u001b[0m     \u001b[0;32mwith\u001b[0m \u001b[0mgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mas_default\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 427\u001b[0;31m       \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fetch_mapper\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_FetchMapper\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfor_fetch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetches\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    428\u001b[0m     \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fetches\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    429\u001b[0m     \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_targets\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36mfor_fetch\u001b[0;34m(fetch)\u001b[0m\n\u001b[1;32m    243\u001b[0m     \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtuple\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    244\u001b[0m       \u001b[0;31m# NOTE(touts): This is also the code path for namedtuples.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 245\u001b[0;31m       \u001b[0;32mreturn\u001b[0m \u001b[0m_ListFetchMapper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    246\u001b[0m     \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    247\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0m_DictFetchMapper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, fetches)\u001b[0m\n\u001b[1;32m    350\u001b[0m     \"\"\"\n\u001b[1;32m    351\u001b[0m     \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fetch_type\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetches\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 352\u001b[0;31m     \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_mappers\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0m_FetchMapper\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfor_fetch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mfetch\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfetches\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    353\u001b[0m     \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_unique_fetches\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_value_indices\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_uniquify_fetches\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_mappers\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    354\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36mfor_fetch\u001b[0;34m(fetch)\u001b[0m\n\u001b[1;32m    244\u001b[0m       \u001b[0;31m# NOTE(touts): This is also the code path for namedtuples.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    245\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0m_ListFetchMapper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 246\u001b[0;31m     \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    247\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0m_DictFetchMapper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfetch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    248\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "split_fit_plot_predict(cnn_model,  hiv_sequences, hiv_maccs, hiv_active, hiv_vocab_size, max_len_hiv, \"hiv\", batch_size=4,epochs=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense_37 (Dense)             (None, 512)               86016     \n",
      "_________________________________________________________________\n",
      "dropout_13 (Dropout)         (None, 512)               0         \n",
      "_________________________________________________________________\n",
      "dense_38 (Dense)             (None, 256)               131328    \n",
      "_________________________________________________________________\n",
      "dropout_14 (Dropout)         (None, 256)               0         \n",
      "_________________________________________________________________\n",
      "dense_39 (Dense)             (None, 64)                16448     \n",
      "_________________________________________________________________\n",
      "dense_40 (Dense)             (None, 1)                 65        \n",
      "_________________________________________________________________\n",
      "dense_41 (Dense)             (None, 1)                 2         \n",
      "=================================================================\n",
      "Total params: 233,859\n",
      "Trainable params: 233,859\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 1731 samples, validate on 433 samples\n",
      "Epoch 1/20\n",
      "1731/1731 [==============================] - 1s 747us/step - loss: 0.6013 - acc: 0.6690 - val_loss: 0.5073 - val_acc: 0.7413\n",
      "Epoch 2/20\n",
      "1731/1731 [==============================] - 0s 46us/step - loss: 0.4591 - acc: 0.7857 - val_loss: 0.4990 - val_acc: 0.7667\n",
      "Epoch 3/20\n",
      "1731/1731 [==============================] - 0s 58us/step - loss: 0.3754 - acc: 0.8411 - val_loss: 0.4731 - val_acc: 0.7667\n",
      "Epoch 4/20\n",
      "1731/1731 [==============================] - 0s 59us/step - loss: 0.3202 - acc: 0.8556 - val_loss: 0.4655 - val_acc: 0.8060\n",
      "Epoch 5/20\n",
      "1731/1731 [==============================] - 0s 61us/step - loss: 0.2726 - acc: 0.8839 - val_loss: 0.4691 - val_acc: 0.8152\n",
      "Epoch 6/20\n",
      "1731/1731 [==============================] - 0s 61us/step - loss: 0.2183 - acc: 0.9122 - val_loss: 0.4858 - val_acc: 0.8176\n",
      "Epoch 7/20\n",
      "1731/1731 [==============================] - 0s 61us/step - loss: 0.1787 - acc: 0.9353 - val_loss: 0.5011 - val_acc: 0.8314\n",
      "Epoch 8/20\n",
      "1731/1731 [==============================] - 0s 54us/step - loss: 0.1372 - acc: 0.9515 - val_loss: 0.5736 - val_acc: 0.8014\n",
      "Epoch 9/20\n",
      "1731/1731 [==============================] - 0s 57us/step - loss: 0.1215 - acc: 0.9555 - val_loss: 0.6149 - val_acc: 0.8129\n",
      "Epoch 10/20\n",
      "1731/1731 [==============================] - 0s 63us/step - loss: 0.0950 - acc: 0.9653 - val_loss: 0.6008 - val_acc: 0.8383\n",
      "Epoch 11/20\n",
      "1731/1731 [==============================] - 0s 61us/step - loss: 0.0865 - acc: 0.9676 - val_loss: 0.6649 - val_acc: 0.8245\n",
      "Epoch 12/20\n",
      "1731/1731 [==============================] - 0s 64us/step - loss: 0.0582 - acc: 0.9827 - val_loss: 0.6899 - val_acc: 0.8268\n",
      "Epoch 13/20\n",
      "1731/1731 [==============================] - 0s 59us/step - loss: 0.0487 - acc: 0.9861 - val_loss: 0.6933 - val_acc: 0.8314\n",
      "Epoch 14/20\n",
      "1731/1731 [==============================] - 0s 60us/step - loss: 0.0321 - acc: 0.9896 - val_loss: 0.7520 - val_acc: 0.8268\n",
      "Epoch 15/20\n",
      "1731/1731 [==============================] - 0s 59us/step - loss: 0.0332 - acc: 0.9931 - val_loss: 0.9112 - val_acc: 0.8245\n",
      "Epoch 16/20\n",
      "1731/1731 [==============================] - 0s 64us/step - loss: 0.0443 - acc: 0.9861 - val_loss: 0.7988 - val_acc: 0.8406\n",
      "Epoch 17/20\n",
      "1731/1731 [==============================] - 0s 60us/step - loss: 0.0422 - acc: 0.9873 - val_loss: 0.7806 - val_acc: 0.8337\n",
      "Epoch 18/20\n",
      "1731/1731 [==============================] - 0s 57us/step - loss: 0.0222 - acc: 0.9954 - val_loss: 0.8783 - val_acc: 0.8291\n",
      "Epoch 19/20\n",
      "1731/1731 [==============================] - 0s 63us/step - loss: 0.0253 - acc: 0.9931 - val_loss: 0.9360 - val_acc: 0.8106\n",
      "Epoch 20/20\n",
      "1731/1731 [==============================] - 0s 62us/step - loss: 0.0400 - acc: 0.9850 - val_loss: 0.9574 - val_acc: 0.8291\n"
     ]
    }
   ],
   "source": [
    "model = mlp_model()\n",
    "history = model.fit(X2_train_hiv, y_train_hiv, shuffle=True, validation_split=0.2, \\\n",
    "                        epochs=20, batch_size=128, verbose=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_4 (Embedding)      (None, 400, 32)           1728      \n",
      "_________________________________________________________________\n",
      "conv1d_4 (Conv1D)            (None, 400, 32)           3104      \n",
      "_________________________________________________________________\n",
      "max_pooling1d_4 (MaxPooling1 (None, 200, 32)           0         \n",
      "_________________________________________________________________\n",
      "lstm_4 (LSTM)                (None, 100)               53200     \n",
      "_________________________________________________________________\n",
      "dense_4 (Dense)              (None, 1)                 101       \n",
      "=================================================================\n",
      "Total params: 58,133\n",
      "Trainable params: 58,133\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 1731 samples, validate on 433 samples\n",
      "Epoch 1/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.6900 - precision: 0.4659 - recall: 0.9261 - auc: 0.4882 - val_loss: 0.6658 - val_precision: 0.4960 - val_recall: 1.0000 - val_auc: 0.5943\n",
      "Epoch 2/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.6346 - precision: 0.4979 - recall: 1.0000 - auc: 0.6431 - val_loss: 0.5738 - val_precision: 0.4954 - val_recall: 1.0000 - val_auc: 0.6686\n",
      "Epoch 3/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.5885 - precision: 0.4953 - recall: 1.0000 - auc: 0.6884 - val_loss: 0.5917 - val_precision: 0.4952 - val_recall: 1.0000 - val_auc: 0.6990\n",
      "Epoch 4/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.5881 - precision: 0.4954 - recall: 1.0000 - auc: 0.7080 - val_loss: 0.5697 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.7137\n",
      "Epoch 5/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.5761 - precision: 0.4955 - recall: 1.0000 - auc: 0.7201 - val_loss: 0.5388 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.7257\n",
      "Epoch 6/20\n",
      "1731/1731 [==============================] - 3s 2ms/step - loss: 0.5550 - precision: 0.4949 - recall: 1.0000 - auc: 0.7312 - val_loss: 0.5214 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.7371\n",
      "Epoch 7/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.5426 - precision: 0.4957 - recall: 1.0000 - auc: 0.7429 - val_loss: 0.5170 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7466\n",
      "Epoch 8/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.5282 - precision: 0.4950 - recall: 1.0000 - auc: 0.7507 - val_loss: 0.5056 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7557\n",
      "Epoch 9/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.5172 - precision: 0.4950 - recall: 1.0000 - auc: 0.7595 - val_loss: 0.4952 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7637\n",
      "Epoch 10/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.5070 - precision: 0.4948 - recall: 1.0000 - auc: 0.7671 - val_loss: 0.4941 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7708\n",
      "Epoch 11/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4952 - precision: 0.4950 - recall: 1.0000 - auc: 0.7738 - val_loss: 0.4970 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7775\n",
      "Epoch 12/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4899 - precision: 0.4949 - recall: 1.0000 - auc: 0.7804 - val_loss: 0.4938 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7835\n",
      "Epoch 13/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4880 - precision: 0.4950 - recall: 1.0000 - auc: 0.7858 - val_loss: 0.4879 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7884\n",
      "Epoch 14/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4675 - precision: 0.4951 - recall: 1.0000 - auc: 0.7909 - val_loss: 0.5124 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7939\n",
      "Epoch 15/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4639 - precision: 0.4951 - recall: 1.0000 - auc: 0.7960 - val_loss: 0.5112 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7985\n",
      "Epoch 16/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4898 - precision: 0.4950 - recall: 1.0000 - auc: 0.8000 - val_loss: 0.4917 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8014\n",
      "Epoch 17/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4807 - precision: 0.4950 - recall: 1.0000 - auc: 0.8028 - val_loss: 0.4934 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8042\n",
      "Epoch 18/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4609 - precision: 0.4950 - recall: 1.0000 - auc: 0.8060 - val_loss: 0.4935 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8076\n",
      "Epoch 19/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4450 - precision: 0.4952 - recall: 1.0000 - auc: 0.8091 - val_loss: 0.4876 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8111\n",
      "Epoch 20/20\n",
      "1731/1731 [==============================] - 4s 2ms/step - loss: 0.4324 - precision: 0.4949 - recall: 1.0000 - auc: 0.8125 - val_loss: 0.5009 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8146\n"
     ]
    }
   ],
   "source": [
    "model = cnn_rnn_model(vocab=hiv_vocab_size,max_len=max_len_hiv)\n",
    "history = model.fit(X1_train_hiv, y_train_hiv, shuffle=True, validation_split=0.2, \\\n",
    "                        epochs=20, batch_size=128, verbose=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "merge_6 (Merge)              (None, 128)               0         \n",
      "_________________________________________________________________\n",
      "dense_30 (Dense)             (None, 64)                8256      \n",
      "_________________________________________________________________\n",
      "dropout_12 (Dropout)         (None, 64)                0         \n",
      "_________________________________________________________________\n",
      "dense_31 (Dense)             (None, 1)                 65        \n",
      "=================================================================\n",
      "Total params: 271,777\n",
      "Trainable params: 271,777\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 1731 samples, validate on 433 samples\n",
      "Epoch 1/20\n",
      "1731/1731 [==============================] - 6s 3ms/step - loss: 0.5692 - precision: 0.4479 - recall: 0.9261 - auc: 0.6696 - val_loss: 0.5185 - val_precision: 0.4960 - val_recall: 1.0000 - val_auc: 0.7879\n",
      "Epoch 2/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.4322 - precision: 0.4940 - recall: 1.0000 - auc: 0.8183 - val_loss: 0.5057 - val_precision: 0.4954 - val_recall: 1.0000 - val_auc: 0.8345\n",
      "Epoch 3/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.3787 - precision: 0.4966 - recall: 1.0000 - auc: 0.8486 - val_loss: 0.4600 - val_precision: 0.4952 - val_recall: 1.0000 - val_auc: 0.8588\n",
      "Epoch 4/20\n",
      "1731/1731 [==============================] - 4s 3ms/step - loss: 0.3108 - precision: 0.4960 - recall: 1.0000 - auc: 0.8696 - val_loss: 0.4680 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.8790\n",
      "Epoch 5/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.2571 - precision: 0.4945 - recall: 1.0000 - auc: 0.8878 - val_loss: 0.4621 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.8952\n",
      "Epoch 6/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.2132 - precision: 0.4960 - recall: 1.0000 - auc: 0.9017 - val_loss: 0.5217 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.9082\n",
      "Epoch 7/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.1583 - precision: 0.4953 - recall: 1.0000 - auc: 0.9131 - val_loss: 0.5399 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9192\n",
      "Epoch 8/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.1200 - precision: 0.4951 - recall: 1.0000 - auc: 0.9235 - val_loss: 0.5983 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9283\n",
      "Epoch 9/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0828 - precision: 0.4949 - recall: 1.0000 - auc: 0.9317 - val_loss: 0.6947 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9358\n",
      "Epoch 10/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0662 - precision: 0.4951 - recall: 1.0000 - auc: 0.9382 - val_loss: 0.7106 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9418\n",
      "Epoch 11/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0471 - precision: 0.4950 - recall: 1.0000 - auc: 0.9439 - val_loss: 0.9716 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9466\n",
      "Epoch 12/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0583 - precision: 0.4953 - recall: 1.0000 - auc: 0.9477 - val_loss: 0.9661 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9499\n",
      "Epoch 13/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0480 - precision: 0.4950 - recall: 1.0000 - auc: 0.9507 - val_loss: 0.7965 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9528\n",
      "Epoch 14/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0402 - precision: 0.4951 - recall: 1.0000 - auc: 0.9538 - val_loss: 0.8546 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9555\n",
      "Epoch 15/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0351 - precision: 0.4949 - recall: 1.0000 - auc: 0.9563 - val_loss: 0.9491 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9578\n",
      "Epoch 16/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0345 - precision: 0.4951 - recall: 1.0000 - auc: 0.9583 - val_loss: 0.9228 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9596\n",
      "Epoch 17/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0327 - precision: 0.4952 - recall: 1.0000 - auc: 0.9601 - val_loss: 0.9606 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9612\n",
      "Epoch 18/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0215 - precision: 0.4953 - recall: 1.0000 - auc: 0.9617 - val_loss: 0.9205 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9628\n",
      "Epoch 19/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0184 - precision: 0.4949 - recall: 1.0000 - auc: 0.9632 - val_loss: 0.9626 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9641\n",
      "Epoch 20/20\n",
      "1731/1731 [==============================] - 5s 3ms/step - loss: 0.0147 - precision: 0.4950 - recall: 1.0000 - auc: 0.9645 - val_loss: 1.0152 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.9654\n"
     ]
    }
   ],
   "source": [
    "model = merged_model(vocab=hiv_vocab_size,max_len=max_len_hiv)\n",
    "history = model.fit([X1_train_hiv,X2_train_hiv], y_train_hiv, shuffle=True, validation_split=0.2, \\\n",
    "                        epochs=20, batch_size=128, verbose=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_42 (Embedding)     (None, 400, 32)           1728      \n",
      "_________________________________________________________________\n",
      "conv1d_66 (Conv1D)           (None, 400, 32)           3104      \n",
      "_________________________________________________________________\n",
      "max_pooling1d_66 (MaxPooling (None, 200, 32)           0         \n",
      "_________________________________________________________________\n",
      "conv1d_67 (Conv1D)           (None, 200, 32)           3104      \n",
      "_________________________________________________________________\n",
      "max_pooling1d_67 (MaxPooling (None, 100, 32)           0         \n",
      "_________________________________________________________________\n",
      "flatten_33 (Flatten)         (None, 3200)              0         \n",
      "_________________________________________________________________\n",
      "dense_42 (Dense)             (None, 1)                 3201      \n",
      "=================================================================\n",
      "Total params: 11,137\n",
      "Trainable params: 11,137\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 1731 samples, validate on 433 samples\n",
      "Epoch 1/20\n",
      "1731/1731 [==============================] - 2s 1ms/step - loss: 0.6843 - precision: 0.4742 - recall: 0.9261 - auc: 0.5766 - val_loss: 0.6620 - val_precision: 0.4960 - val_recall: 1.0000 - val_auc: 0.6650\n",
      "Epoch 2/20\n",
      "1731/1731 [==============================] - 0s 96us/step - loss: 0.6321 - precision: 0.4996 - recall: 1.0000 - auc: 0.6873 - val_loss: 0.5878 - val_precision: 0.4954 - val_recall: 1.0000 - val_auc: 0.6947\n",
      "Epoch 3/20\n",
      "1731/1731 [==============================] - 0s 102us/step - loss: 0.5977 - precision: 0.4948 - recall: 1.0000 - auc: 0.6985 - val_loss: 0.5698 - val_precision: 0.4952 - val_recall: 1.0000 - val_auc: 0.7029\n",
      "Epoch 4/20\n",
      "1731/1731 [==============================] - 0s 99us/step - loss: 0.5801 - precision: 0.4937 - recall: 1.0000 - auc: 0.7109 - val_loss: 0.5687 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.7170\n",
      "Epoch 5/20\n",
      "1731/1731 [==============================] - 0s 102us/step - loss: 0.5779 - precision: 0.4953 - recall: 1.0000 - auc: 0.7205 - val_loss: 0.5601 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.7263\n",
      "Epoch 6/20\n",
      "1731/1731 [==============================] - 0s 100us/step - loss: 0.5761 - precision: 0.4955 - recall: 1.0000 - auc: 0.7291 - val_loss: 0.5410 - val_precision: 0.4951 - val_recall: 1.0000 - val_auc: 0.7332\n",
      "Epoch 7/20\n",
      "1731/1731 [==============================] - 0s 104us/step - loss: 0.5573 - precision: 0.4950 - recall: 1.0000 - auc: 0.7368 - val_loss: 0.5334 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7412\n",
      "Epoch 8/20\n",
      "1731/1731 [==============================] - 0s 100us/step - loss: 0.5440 - precision: 0.4946 - recall: 1.0000 - auc: 0.7456 - val_loss: 0.5241 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7486\n",
      "Epoch 9/20\n",
      "1731/1731 [==============================] - 0s 99us/step - loss: 0.5310 - precision: 0.4957 - recall: 1.0000 - auc: 0.7523 - val_loss: 0.5119 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7559\n",
      "Epoch 10/20\n",
      "1731/1731 [==============================] - 0s 103us/step - loss: 0.5210 - precision: 0.4952 - recall: 1.0000 - auc: 0.7595 - val_loss: 0.5032 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7630\n",
      "Epoch 11/20\n",
      "1731/1731 [==============================] - 0s 99us/step - loss: 0.5097 - precision: 0.4948 - recall: 1.0000 - auc: 0.7663 - val_loss: 0.4975 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7696\n",
      "Epoch 12/20\n",
      "1731/1731 [==============================] - 0s 97us/step - loss: 0.5009 - precision: 0.4951 - recall: 1.0000 - auc: 0.7723 - val_loss: 0.4932 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7756\n",
      "Epoch 13/20\n",
      "1731/1731 [==============================] - 0s 100us/step - loss: 0.4926 - precision: 0.4947 - recall: 1.0000 - auc: 0.7787 - val_loss: 0.4893 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7811\n",
      "Epoch 14/20\n",
      "1731/1731 [==============================] - 0s 100us/step - loss: 0.4821 - precision: 0.4950 - recall: 1.0000 - auc: 0.7842 - val_loss: 0.4848 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7865\n",
      "Epoch 15/20\n",
      "1731/1731 [==============================] - 0s 97us/step - loss: 0.4750 - precision: 0.4953 - recall: 1.0000 - auc: 0.7890 - val_loss: 0.4898 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7914\n",
      "Epoch 16/20\n",
      "1731/1731 [==============================] - 0s 99us/step - loss: 0.4646 - precision: 0.4951 - recall: 1.0000 - auc: 0.7936 - val_loss: 0.4804 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.7961\n",
      "Epoch 17/20\n",
      "1731/1731 [==============================] - 0s 102us/step - loss: 0.4546 - precision: 0.4952 - recall: 1.0000 - auc: 0.7986 - val_loss: 0.4770 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8007\n",
      "Epoch 18/20\n",
      "1731/1731 [==============================] - 0s 99us/step - loss: 0.4457 - precision: 0.4951 - recall: 1.0000 - auc: 0.8028 - val_loss: 0.4755 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8051\n",
      "Epoch 19/20\n",
      "1731/1731 [==============================] - 0s 105us/step - loss: 0.4434 - precision: 0.4949 - recall: 1.0000 - auc: 0.8073 - val_loss: 0.4904 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8089\n",
      "Epoch 20/20\n",
      "1731/1731 [==============================] - 0s 98us/step - loss: 0.4340 - precision: 0.4948 - recall: 1.0000 - auc: 0.8106 - val_loss: 0.4742 - val_precision: 0.4950 - val_recall: 1.0000 - val_auc: 0.8125\n"
     ]
    }
   ],
   "source": [
    "model = cnn_model(vocab=hiv_vocab_size,max_len=max_len_hiv)\n",
    "history = model.fit(X1_train_hiv, y_train_hiv, shuffle=True, validation_split=0.2, \\\n",
    "                        epochs=20, batch_size=128, verbose=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10282/10282 [==============================] - 1s 99us/step\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.9678078194903715"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "model.evaluate(X1_test_hiv,y_test_hiv)[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'list' object has no attribute 'dtype'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-222-ca875fa45347>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0my_prob\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX1_test_hiv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0my_predict_hiv\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0my_prob\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mauc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_predict_hiv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_test_hiv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-198-0278199900eb>\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(self, args, **kwargs)\u001b[0m\n\u001b[1;32m      6\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      7\u001b[0m         \u001b[0;34m\"\"\" Wrapper for turning tensorflow metrics into keras metrics \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m         \u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mupdate_op\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      9\u001b[0m         \u001b[0mK\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_session\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlocal_variables_initializer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     10\u001b[0m         \u001b[0;32mwith\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontrol_dependencies\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mupdate_op\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/metrics_impl.pyc\u001b[0m in \u001b[0;36mauc\u001b[0;34m(labels, predictions, weights, num_thresholds, metrics_collections, updates_collections, curve, name, summation_method)\u001b[0m\n\u001b[1;32m    660\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    661\u001b[0m     values, update_ops = _confusion_matrix_at_thresholds(\n\u001b[0;32m--> 662\u001b[0;31m         labels, predictions, thresholds, weights)\n\u001b[0m\u001b[1;32m    663\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    664\u001b[0m     \u001b[0;31m# Add epsilons to avoid dividing by 0.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/metrics_impl.pyc\u001b[0m in \u001b[0;36m_confusion_matrix_at_thresholds\u001b[0;34m(labels, predictions, thresholds, weights, includes)\u001b[0m\n\u001b[1;32m    467\u001b[0m       check_ops.assert_greater_equal(\n\u001b[1;32m    468\u001b[0m           \u001b[0mpredictions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 469\u001b[0;31m           \u001b[0mmath_ops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcast\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0.0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpredictions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    470\u001b[0m           message='predictions must be in [0, 1]'),\n\u001b[1;32m    471\u001b[0m       check_ops.assert_less_equal(\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'dtype'"
     ]
    }
   ],
   "source": [
    "y_prob = model.predict(X1_test_hiv)\n",
    "y_predict_hiv = y_prob.argmax(axis=-1)\n",
    "auc(y_predict_hiv, y_test_hiv)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
